home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 10
/
AACD 10.iso
/
AACD
/
Magazine
/
Online
/
httpproxy
/
updateCache.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1996-08-20
|
6KB
|
246 lines
/* Update the cache directory. */
/* Usage: rx updateCache.rexx CACHEDIRNAME/A DODELETES/S*/
/* CACHEDIRNAME: cache directory name
* DODELETES: delete old directory */
/* All Files will converted either
* a) from old style to new style or
* b) from new style(1) to new style(2) (a newer one)
*/
/* Only security checks:
* a) existence of '.iscachedir'
* b) cache version number residing in @cachever */
/* !!! httpresolve and delete have to be found in ram: !!!
* for mode b) old_httpresolve has to be found in ram:, too. */
parse arg dir dodeletes
dodeletes = upper(dodeletes)
address command
options failat 21
if ~show('L','rexxarplib.library') then call addlib('rexxarplib.library',0,-30,0)
if ~show('L','rexxsupport.library') then call addlib('rexxsupport.library',0,-30,0)
say "This script might generate some dos errors. Please ignore..."
/* create dir arguments */
if right(dir,1) = ":" then
do
olddir = dir
newdir = dir || "@new"
end
else
do
olddir = dir || "/"
newdir = dir || "@new"
if right(dir,1) = "/" then
do
olddir = dir
newdir = left(dir, length(dir)-1) || "@new"
end
end
say "cache directory: "olddir " --- temporary new directory: "newdir"/"
/* Conversion style check: style = 1: a) style = 2: b) */
style = 0
if exists(olddir".iscachedir") then
style = 1
else
do
if exists(olddir"@dirurl") then
do
style = 2
if exists(olddir"@cachever") then
do
if ~ open('s', olddir"@cachever") then
exit 20
cachever = readln('s')
call close('s')
"ram:old_httpresolve >t:httpproxy_ver version"
if ~ open('s', "t:httpproxy_ver") then
exit 20
oldver = readln('s')
call close('s')
"ram:httpresolve >t:httpproxy_ver version"
if ~ open('s', "t:httpproxy_ver") then
exit 20
newver = readln('s')
call close('s')
"delete t:httpproxy_ver"
if (cachever = newver) then
do
say "*** cache dir does not need any conversion. ***"
exit 0
end
if (cachever ~= oldver) then
do
say "*** cache version and old httpresolve utility not equal -> cannot update cache ***"
exit 20
end
end
end
end
if (style = 0) then
do
say "*** not a cache directory. exiting. ***"
exit 20
end
/* Consistency checks */
if ~exists("ram:httpresolve") then
"copy quiet amitcp:bin/httpresolve amitcp:bin/old_httpresolve ram:"
if ~exists("ram:httpresolve") then
do
say "*** error: cannot find httpresolve in ram: ***"
exit 20
end
if (style = 2) & ~exists("ram:old_httpresolve") then
do
say "*** error: cannot find old httpresolve in ram: as old_httpresolve ***"
exit 20
end
"copy c:delete ram:"
/* generate new cache directory */
if exists(left(olddir, length(olddir)-1)".old") then
"ram:delete "left(olddir, length(olddir)-1)".old all quiet"
if exists(newdir) then
"ram:delete "newdir" all quiet"
"makedir "newdir
newdir = newdir || "/"
/* Generate special files and directories */
"echo >"newdir"@dirurl"
"makedir "newdir"@temp "newdir"@trash"
/* open move script for all cache files related to some URL files */
if ~ open('s', "t:httpproxy_script", w) then
do
say "*** error: cannot open temporary file ***"
exit 10
end
call writeln('s',"failat 21")
call writeln('s',"cd "newdir) /* needed for httpresolve */
/* generate file list */
say "analysing directory..."
lastdir = pragma(D, olddir)
if style = 1 then
do
NumFiles = FileList("@????????.????????", FList, F, N)
end
else
if style = 2 then
do
todo = 1 /* non-rekursive rekursive file tree walker */
Dirs.1 = ""
i = 1
do while todo > 0
CurDir = Dirs.todo
Num = FileList(CurDir"#?", IList, D, N)
do j = 1 to Num
Dirs.todo = CurDir || IList.j"/"
todo = todo + 1
end
todo = todo - 1
Num = FileList(CurDir"#?@", IList, F, N)
do j = 1 to Num
if substr(IList.j, 1, 2) ~= "@@" then
do
FList.i = CurDir || IList.j
i = i + 1
end
end
end
NumFiles = i - 1
end
realdir = pragma(D, lastdir)
if (right(realdir,1) ~= "/") & (right(realdir,1) ~= ":") then
realdir = realdir || "/"
/* generate move script */
say "generating move script..."
if style = 1 then
do
do i=1 to NumFiles
if substr(FList.i, 1, 1) ~= "@" then
exit 10
if exists(realdir"_"substr(FList.i, 2)) then
do
if open('f', realdir || FList.i, R) then
do
url = readln('f')
call close('f')
if (url ~= "") then
do
call writeln('s',"ram:httpresolve <"""realdir"_"substr(FList.i, 2)""" SAVE URL """url"""")
if (dodeletes = "DODELETES") then
call writeln('s',"ram:delete quiet file """realdir"_"substr(FList.i, 2)"""")
end
end
end
end
end
else
if style = 2 then
do
call pragma(D, olddir) /* needed for old httpresolve */
do i=1 to NumFiles
"ram:old_httpresolve >t:httpproxy_result file """FList.i""""
if open('f', "t:httpproxy_result", R) then
do
url = readln('f')
call close('f')
if (url ~= "") then
do
call writeln('s',"ram:httpresolve <"""realdir || FList.i""" SAVE URL """url"""")
if (dodeletes = "DODELETES") then
call writeln('s',"ram:delete quiet file """realdir || FList.i"""")
end
end
end
end
/* perform move action */
say "performing moves..."
call close('s')
call pragma(D, lastdir)
"execute t:httpproxy_script"
call pragma(D, newdir)
"ram:httpresolve >@cachever version"
call pragma(D, lastdir)
"c:copy msg "newdir"@msg all" /* copy message files */
/* Delete old special files, url files and remaining (unrelated) cache files */
"ram:delete >nil: t:httpproxy_result t:httpproxy_script"
if dodeletes = "DODELETES" then
do
say "deleting old files..."
"ram:delete >nil: "olddir".#?"
if style = 1 then
do
"ram:delete >nil: "olddir"@?????????????????"
"ram:delete >nil: "olddir"_?????????????????"
end
else
"ram:delete >nil: "olddir"~(@new) all"
end
/* Try to delete old cache directory but keep in case of non-emptyness.. */
"ram:delete "left(olddir, length(olddir)-1) "quiet"
if exists(left(olddir, length(olddir)-1)) then
"rename >nil: "left(olddir, length(olddir)-1) left(olddir, length(olddir)-1)".old"
if right(olddir, 1) ~= ":" then
"rename "left(newdir, length(newdir)-1) left(olddir, length(olddir)-1)
if exists(newdir) then
do
"rename "newdir"#? "olddir "quiet" /* move them to new directory */
"ram:delete "newdir "quiet"
end
say "*** done. ***"
exit 0